from serial_sentence_io import serial_sentence_io
import nmea2kdb
import json

class driver(serial_sentence_io):

	def __init__(self,*m):
		self.n2kdb = nmea2kdb.N2KDB()#self.message_callback)
		serial_sentence_io.__init__(self,*m)

	def send(self, data):
		'''Do validation of s08dz data format (basically NMEA
		2k) before passing out to our base serial I/O class'''

		# FIXME: validate data

		serial_sentence_io.send(data)

	def read(self, fd):
		sentences = serial_sentence_io.read(self, fd)
		if sentences:
			# FIXME: make any necessary adjustments to the
			# sentence before publishing it
			for S in sentences:
				self.publisher.publish_sentence(self.name, S) 
				d = self.n2kdb.received_str(S)
				self.publisher.publish_sentence(self.name,json.dumps(d.getdict()))

	def message_callback(self,m):
		self.publisher.publish_sentence(self.name, json.dumps(m))
